#include<iostream>
#include<exception>
//3
class MyException:public std::exception//自定义异常类
{
public:
    MyException(const::std::string&str)
    {
        this->str=str;
    }
    virtual const char *what() const noexcept//noxcept：：当前函数不会抛出异常
    {

            std::cout<<"这是我自己的异常类！\n";
            return str.c_str();
    }
private:
    std::string str;

}











int divide(int a,int b)
{
  if(b==0)
        throw MyException("除数异常");
   return a/b;
}

int main()
{
    try
    {
        divide(1,0);
    }
    catch(const std::exception& e)
    {
        std::cerr<<e.what()<<'\n';
    }

    return 0;
}